from pymongo import MongoClient

def set_all_users_logged_out():
    # 连接到MongoDB
    client = MongoClient("mongodb://192.168.168.110:27017/")
    
    # 选择数据库
    db = client['data']

    # 更新所有用户的is_logged_in字段为False
    result = db.user.update_many({}, {"$set": {"is_logged_in": True}})

    # 输出更新的用户数量
    print(f"已更新 {result.modified_count} 个用户的登录状态为未登录。")

    client.close()

# 主程序
if __name__ == "__main__":
    set_all_users_logged_out()
